let app = getApp()
Page({
  data: {
    loading: 1
  },
  onLoad(options) {
     // console.log(options)
    let that = this;
    this.setData({
      inspectPlanId: options.inspectPlanId,
      hide: 0,
      categoryId: options.categoryId
    })
  },
  onShow: function() {
    this.setData({
      hide: 0
    })
    dd.httpRequest({
      url: app.baseUrl + '/DingDingSystem2/getInspectInfoByPlanId',
      method: 'POST',
      headers:{
        "Content-Type":"application/json"
      },
      data:JSON.stringify(parseInt(this.data.inspectPlanId)),
      dataType: 'json',
      success: res => {
        console.log(res.data)
        for (let i = 0; i < res.data.length; i++) {
          res.data[i].categoryId = parseInt(this.data.categoryId)
          let photo = res.data[i].photo.split(",")
          if (photo[0] == "") {
            res.data[i].nophoto = 1
          } else {
            for (let o in photo) {
              photo[o] = app.imageUrl + photo[o]
            }
          }
          res.data[i].photo = photo
          let modifyTime = res.data[i].modifyTime,
            modifyDate = modifyTime.split(" ")[0].split("-")
          if (res.data[i].updateUserName) {
            res.data[i].updateInfo = "此记录已于当日" + modifyTime.substr(11, 2) + "时" + modifyTime.substr(14, 2) + "分被" + res.data[i].updateUserName + "修改"
          }
          if (res.data[i].status == 5) {
            res.data[i].updateInfo = `此记录已于${modifyDate[1]}月${modifyDate[2]}日${modifyTime.substr(11, 2)}时${modifyTime.substr(14, 2)}分被${res.data[i].updateUserName}处理`
          }

          if(res.data[i].video != ""){
            res.data[i].videoSrc = app.imageUrl + res.data[i].video 
          }
        }
        let timeDay = res.data[0].createTime.substr(0, 10).split("-"),
          timeMin = res.data[0].createTime.substr(11, 5).split(":"),
          checkTime = timeDay[0] + "年" + timeDay[1] + "月" + timeDay[2] + "日" + timeMin[0] + "时" + timeMin[1] + "分"
        this.setData({
          createUser: res.data[0].createUserName,
          phone: res.data[0].phone,
          time: checkTime,
          item: res.data[0].item,
          contentList: res.data
        })
        dd.hideLoading()
      },
      fail: res => {
        dd.showToast({
          content: '网络异常！',
          type: 'fail'
        })
      },
      complete: () => {
        this.setData({
          loading: 0
        })
      }
    })
  },

  previewImageDeal: function(e) {
    let detailIndex = parseInt(e.currentTarget.id.split('-')[0])
    let imageIndex = parseInt(e.currentTarget.id.split('-')[1])
    let current = this.data.contentList[detailIndex].photo
    dd.previewImage({
      current: current[imageIndex], // 当前显示图片的http链接
      urls: current // 需要预览的图片http链接列表
    })
  },

  updateInspectCondition: function(e) {
    let date = new Date();
     console.log(this.data.contentList[e.currentTarget.id])
    let list = this.data.contentList[e.currentTarget.id]
    if (parseInt(date.getDate()) == parseInt(list.createTime.substr(8, 2)) && this.data.contentList[e.currentTarget.id].status != 5) {
      dd.confirm({
        title:"温馨提示",
        content: "是否要对此排查内容进行修改？",
        confirmButtonText: '是',
        cancelButtonText: '否',
        success:(result) =>{
          if (result.confirm) {
            dd.setStorage({
              key: "updateInspect" + list.id,
              data: list,
              success(res) {
                dd.navigateTo({
                  url: '../../page/workInspectUpdate/workInspectUpdate?id=' + list.id,
                })
              },
              fail() {
                dd.showToast({
                  content: '异常错误',
                  type: 'fail'
                })
              }
            })
          }
        }
      })
    } else {
      dd.showToast({
        content: '超过规定修改时间！',
        type: "fail",
        mask: true
      })
    }

  },

  phoneCall: function() {
    dd.makePhoneCall({
      phoneNumber: this.data.phone
    })
  },

  notice: function() {
    this.data.hide == 0 ?
      this.setData({
        hide: 1
      }) :
      this.data.hide == 1 ? this.setData({
        hide: 2
      }) : this.setData({
        hide: 1
      })
  }
  
  
});